<html>
<head><meta charset="utf-8"><title>issue-52663-future-loop-iteration · t-compiler/wg-nll · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/index.html">t-compiler/wg-nll</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html">issue-52663-future-loop-iteration</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="130712997"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130712997" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130712997">(Aug 01 2018 at 13:19)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> I was planning to experiment with <a href="https://github.com/rust-lang/rust/issues/52663#issuecomment-409023250" target="_blank" title="https://github.com/rust-lang/rust/issues/52663#issuecomment-409023250">this diagnostic improvement</a>. </p>
<p>As far as I can gather, there's no existing code that might help with determining if we're in the "used in future iteration" case - closest I can find is <a href="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/borrow_check/error_reporting.rs#L86-L95" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/librustc_mir/borrow_check/error_reporting.rs#L86-L95">this code</a> but that doesn't seem useful here.</p>
<p>Do you think a reasonable approach to take is to try follow the MIR statements from where the borrow is used through the basic blocks until I can find the borrow use location again (perhaps require that I pass over the borrow being made)? That seems a little contrived but I'm not sure how else I'd determine if the statements are in a loop.</p>



<a name="130713285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713285">(Aug 01 2018 at 13:23)</a>:</h4>
<p>I was wondering if we could get away with just comparing the spans?</p>



<a name="130713355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713355">(Aug 01 2018 at 13:24)</a>:</h4>
<p>How do you mean?</p>



<a name="130713358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713358">(Aug 01 2018 at 13:24)</a>:</h4>
<p>i.e. if the span of the use occurs earlier in the source than that of the borrow, then assume that this can only happen due to loop's iterating</p>



<a name="130713365"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713365" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713365">(Aug 01 2018 at 13:24)</a>:</h4>
<p>and adjust the message accordingly</p>



<a name="130713368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713368">(Aug 01 2018 at 13:24)</a>:</h4>
<p>Ah.</p>



<a name="130713373"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713373" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713373">(Aug 01 2018 at 13:24)</a>:</h4>
<p>Its a hack, I know</p>



<a name="130713379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713379">(Aug 01 2018 at 13:24)</a>:</h4>
<p>I thought about that, but wasn't sure if there were cases I wasn't considering that might trip it up.</p>



<a name="130713394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713394">(Aug 01 2018 at 13:25)</a>:</h4>
<p>so the main case I can think of that might trip that up</p>



<a name="130713397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713397">(Aug 01 2018 at 13:25)</a>:</h4>
<p>I guess I could try it and find out.</p>



<a name="130713403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713403">(Aug 01 2018 at 13:25)</a>:</h4>
<p>would be (maybe) something with <code>if let PAT = EXPR;</code></p>



<a name="130713411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713411">(Aug 01 2018 at 13:25)</a>:</h4>
<p>but I dont think you can have a use in the PAT there...</p>



<a name="130713466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713466">(Aug 01 2018 at 13:26)</a>:</h4>
<p>oh</p>



<a name="130713475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713475">(Aug 01 2018 at 13:26)</a>:</h4>
<p>function_call(..., &amp;something_borrowed, ...)</p>



<a name="130713478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713478">(Aug 01 2018 at 13:26)</a>:</h4>
<p>that might break it</p>



<a name="130713503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713503">(Aug 01 2018 at 13:26)</a>:</h4>
<p>you might have to double check that the <em>end</em> of the use's span occurs before the beginning of the borrow's span</p>



<a name="130713513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713513">(Aug 01 2018 at 13:27)</a>:</h4>
<p>rather than just comparing the starts of the two spans</p>



<a name="130713534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130713534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130713534">(Aug 01 2018 at 13:27)</a>:</h4>
<p>(but maybe try the simpler way first, and just see if you can break it with an example like that.)</p>



<a name="130714543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130714543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130714543">(Aug 01 2018 at 13:42)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> that approach results in <a href="https://github.com/rust-lang/rust/blob/master/src/test/ui/span/send-is-not-static-std-sync-2.rs" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/test/ui/span/send-is-not-static-std-sync-2.rs">this test</a> with no loops changing from <a href="https://github.com/rust-lang/rust/blob/master/src/test/ui/span/send-is-not-static-std-sync-2.nll.stderr" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/test/ui/span/send-is-not-static-std-sync-2.nll.stderr">this result</a> to <a href="https://gist.github.com/davidtwco/0c6db68d89d7e37344e63bba42772d65" target="_blank" title="https://gist.github.com/davidtwco/0c6db68d89d7e37344e63bba42772d65">this result</a>. It also affects <a href="https://github.com/rust-lang/rust/blob/master/src/test/ui/lifetimes/borrowck-let-suggestion.rs" target="_blank" title="https://github.com/rust-lang/rust/blob/master/src/test/ui/lifetimes/borrowck-let-suggestion.rs">this test</a>.</p>



<a name="130714741"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130714741" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130714741">(Aug 01 2018 at 13:46)</a>:</h4>
<p>oh of course</p>



<a name="130714754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130714754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130714754">(Aug 01 2018 at 13:46)</a>:</h4>
<p>you dont' even need <code>if let</code>; just a move does it. Sigh.</p>



<a name="130714877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130714877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130714877">(Aug 01 2018 at 13:48)</a>:</h4>
<p>what a pain</p>



<a name="130722514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130722514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130722514">(Aug 01 2018 at 15:43)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> Submitted <a href="https://github.com/rust-lang/rust/issues/52948" target="_blank" title="https://github.com/rust-lang/rust/issues/52948">#52948</a> for this with my initial suggested approach. I think it caught more cases than the span comparison.</p>



<a name="130723047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130723047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130723047">(Aug 01 2018 at 15:51)</a>:</h4>
<p>oh cool!</p>



<a name="130723073"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130723073" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130723073">(Aug 01 2018 at 15:52)</a>:</h4>
<p>219326</p>



<a name="130738840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130738840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130738840">(Aug 01 2018 at 20:21)</a>:</h4>
<blockquote>
<p>219326</p>
</blockquote>
<p>wait, you've all gotten used to this, right?</p>



<a name="130738923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration/near/130738923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/issue-52663-future-loop-iteration.html#130738923">(Aug 01 2018 at 20:22)</a>:</h4>
<p>I hit that OTP button all the time by accident. Usually I catch it quickly enough to delete it (just to keep noise out of the channel), but this time I failed.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>